﻿@{
    Layout = "";
}
@model SmartStore.DiscountRules.Models.HadSpentAmountModel
@using SmartStore.Web.Framework;
 
<script>
	$(function () {
		var prefix = '@ViewData.TemplateInfo.HtmlFieldPrefix';
		
		window[prefix + '_getSettings'] = function () {
			return JSON.stringify(
            {
                LimitToCurrentBasketSubTotal: $("#@Html.FieldIdFor(model => model.LimitToCurrentBasketSubTotal)").prop('checked')
            });
		};

		$('#@Html.FieldIdFor(model => model.SpentAmount)').on('input', function (e) {
			$('#' + prefix + '_SpentAmountVal').val($(this).val());
		});

		applyCommonPlugins(".discount-rule-wrapper");
	});
</script>

<table class="adminContent discount-rule-wrapper" 
	   data-discount-id='@Model.DiscountId'
	   data-requirement-id='@Model.RequirementId'
	   data-action-url='@Url.Action("HadSpentAmount")'
	   data-fail-msg=@T("Admin.Promotions.Discounts.Requirements.FailedToSave").JsText
	   data-success-msg=@T("Admin.Promotions.Discounts.Requirements.Saved").JsText>
	<tr class="wide">
		<td class="adminTitle">
			@Html.SmartLabelFor(model => model.SpentAmount)
		</td>
		<td class="adminData">
			@Html.Hidden("SpentAmountVal", Model.SpentAmount, new { data_routeparam = "spentAmount" })
			@Html.EditorFor(model => model.SpentAmount)
			@Html.ValidationMessageFor(model => model.SpentAmount)
		</td>
	</tr>
	<tr class="wide">
		<td class="adminTitle">
			@Html.SmartLabelFor(model => model.LimitToCurrentBasketSubTotal)
		</td>
		<td class="adminData">
			@Html.CheckBoxFor(model => model.LimitToCurrentBasketSubTotal, new { data_routeparam = "settings", data_routevalue = ViewData.TemplateInfo.HtmlFieldPrefix + "_getSettings" })
			@Html.ValidationMessageFor(model => model.LimitToCurrentBasketSubTotal)
		</td>
	</tr>
	<tr class="wide">
		<td class="adminTitle">
			&nbsp;
		</td>
		<td class="adminData">
			<button type="button" class="btn @(Model.RequirementId == 0 ? "btn-primary btn-block btn-lg" : "btn-warning") btn-save-discount-rule">
				<i class="fa fa-@(Model.RequirementId == 0 ? "plus" : "check")"></i>
				<span>@T(Model.RequirementId == 0 ? "Common.AddNew" : "Admin.Common.Save")</span>
			</button>
		</td>
	</tr>
</table>